package com.bwie.util.datastructureThree;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.OutputStreamWriter;

public class three {
    public static void main(String[] args) {
        JSONObject data = new JSONObject();
        data.put("name", "张三");
        data.put("age", 25);

        JSONObject address = new JSONObject();
        address.put("city", "上海");
        address.put("state", "奉贤");
        address.put("zip", "10001");
        data.put("address", address);

        JSONArray friends = new JSONArray();

        JSONObject friend1 = new JSONObject();
        friend1.put("name", "李四");
        friend1.put("age", 27);

        JSONObject friend1Address = new JSONObject();
        friend1Address.put("city", "上海");
        friend1Address.put("state", "虹桥");
        friend1Address.put("zip", "10002");
        friend1.put("address", friend1Address);
        friends.add(friend1);

        JSONObject friend2 = new JSONObject();
        friend2.put("name", "王五");
        friend2.put("age", 24);

        JSONObject friend2Address = new JSONObject();
        friend2Address.put("city", "杭州");
        friend2Address.put("state", "西湖");
        friend2Address.put("zip", "20001");
        friend2.put("address", friend2Address);
        friends.add(friend2);

        data.put("friends", friends);

        try (OutputStreamWriter writer = new OutputStreamWriter(System.out, "UTF-8")) {
            writer.write(data.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
